, weights): prob = sigmoid (sum (inx*weights)) if prob > 0.5:return 1.0 else:return 0.0 D EF colictest (): Frtrain = open (' HorseColicTraining.txt '); frtest = open (' horseColicTest.txt ') trainingset = [];
Traininglabels = [] for line in Frtrain.readlines (): Currline = Line.strip (). Split (' \ t ') Linearr =[] For I in range (21):
Linearr.append (float (currline[i)) trainingset.append (Linearr) traininglabels.append (float (CU RRLINE[21]) Trainweights = stocGradAscent1 (
= line.strip().split('\t')53 lineArr =[]54 for i in range(21):55 lineArr.append(float(currLine[i]))56 if int(classifyVector(array(lineArr), trainWeights))!= int(currLine[21]):57 errorCount += 158 errorRate = (float(errorCount)/numTestVec)59 print "the error rate of this test is: %f" % errorRate60 return errorRate61 62 def multiTest():63 numTests = 10; errorSum=0.064 for k in range(nu
), Traininglabels, #训练获得回归系数 errorcount = 0; Numtestvec = 0.0 for line in Frtest.readlines (): #测试样本的测试 Numtestvec + = 1.0 Currline = Line.strip (). Split (' \ t ') Linearr =[] for I in range: Linearr.append (float (currline[i])) if INT (classifyv Ector (Array (Linearr), trainweights))! = Int (currline[21]): Errorcount + = 1 #计算错误率 errorrate = (Float (errorcou NT)/numtestvec) print "The error rate of this test is:%f"% errorrate return errorratedef multitest
') trainingset = [];
Traininglabels = [] for line in Frtrain.readlines (): Currline = Line.strip (). Split (' t ') Linearr =[] for I in range: Linearr.append (float (currline[i)) Trainingset.append (Lin Earr) Traininglabels.append (float (currline[21)) Trainweights = StocGradAscent1 (Array (trainingset), Trainingla BELs, 1000) errorcount = 0;
Numtestvec = 0.0 for line in Frtest.readlines (): Numtestvec + = 1.0 Currline = Line.strip (). Split (' t ') Linearr =[] for I in range: L
Contact Us
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.